from config import HOST


class ApiRegisterLogin:
    def __init__(self, session):
        """获取session"""
        self.session = session
        """图片验证码"""
        self.__url_img_code = HOST + "/common/public/verifycode1/{}"
        """短信验证码"""
        self.__url_phone_code = HOST + "/member/public/sendSms"
        """注册url"""
        self.__url_register = HOST + "/member/public/reg"
        """登录"""
        self.__url_login = HOST + "/member/public/login"
        """验证登录"""
        self.__url_login_status = HOST + "/member/public/islogin"

    def api_img_code(self, random):
        """获取图片验证码接口"""
        return self.session.get(url=self.__url_img_code.format(random))

    def api_phone_code(self, phone, imgVerifycode):
        """短信验证码接口"""

        data = {"phone": phone,
                "imgVerifyCode": imgVerifycode,
                "type": "reg"

                }
        return self.session.post(url=self.__url_phone_code, data=data)

    def api_register(self, phone, password, verifycode, phone_code):
        """注册url接口"""

        data = {
            "phone": phone,
            "password": password,
            "verifycode": verifycode,
            "phone_code": phone_code,
            "dy_server": "on",
            "invite_phone": ""

        }
        return self.session.post(url=self.__url_register, data=data)

    def api_login(self, keywords=15081212877, password="test123"):
        """登录接口"""

        data = {
            "keywords": keywords,
            "password": password
        }
        return self.session.post(url=self.__url_login, data=data)

    def api_status_login(self):
        """查询登入"""

        return self.session.post(url=self.__url_login_status)
